package com.briup.mt.web.controller;

import com.briup.mt.service.ICommentService;
import com.briup.mt.bean.Comment;
import com.briup.mt.utils.Message;
import com.briup.mt.utils.MessageUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private ICommentService commentService;

    @GetMapping("query")
    public Message query(Long id){
        List<Comment>list=commentService.query(id);
        return MessageUtil.success(list);
    }
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Comment comment){
        commentService.saveOrUpdate(comment);
        return  MessageUtil.success("保存成功");
    }
    @DeleteMapping("deleteById")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value="评论编号",required = true,paramType = "query")
    })
    public Message deleteById(@NotNull long id){
        commentService.deleteById(id);
        return MessageUtil.success("删除成功");
    }
}
